@import 'snapcraft_patterns_icons';

@mixin snapcraft-release {
  $color-highlighted: #fae6be;

  // RELEASES CONFIRM

  .p-releases-confirm {
    background: $color-light;
    margin-bottom: 1em;
    padding: 1em;
    position: relative;
  }

  .p-releases-confirm__buttons {
    position: absolute;
    right: 1em;
    top: .625rem;
  }

  // RELEASES TABLE

  .p-releases-table {
    margin-bottom: $spv-outer--medium;
  }

  // row

  .p-releases-table__row {
    display: flex;
    margin-bottom: 2px;
  }

  .p-releases-table__row--channel {
    height: 4rem;
  }

  .p-releases-table__row--branch {
    height: 4rem;

    .p-releases-channel {
      margin-left: 2rem;
      width: calc(280px - 2rem);
    }
  }

  .p-releases-table__row--show-all {
    height: 3rem;
    line-height: 2rem;
    margin-left: 2rem;
  }

  .p-releases-table__row--heading {
    height: 2rem;
  }

  .p-releases-table > h4 {
    margin-top: $spv-outer--shallow-scaleable;
  }

  .p-releases-table__menus {
    margin-left: auto;
    margin-right: -.1rem;
    margin-top: -.1rem;
  }

  .p-releases-table__branches,
  .p-releases-table__branch-timeleft {
    align-items: center;
    background: transparent;
    border-radius: 3px;
    color: $color-dark;
    display: flex;
    font-size: .8rem;
    line-height: .8rem;
    position: absolute;
  }

  .p-releases-table__branches {
    bottom: .2rem;
    cursor: pointer;
    opacity: .6;
    padding: .2rem $sph-inner--small;
    right: .2rem;

    &:hover,
    &.is-open {
      background: $color-x-light;
      opacity: 1;
    }
  }

  .p-releases-table__branch-timeleft {
    bottom: $spv-inner--small;
    right: $sph-inner--small;
  }

  // This is to have different width items depending on
  // the number of architectures
  // See https://www.growingwiththeweb.com/2014/06/detecting-number-of-siblings-with-css.html
  // For more information
  .p-releases-table__row {
    &.p-releases-table__row--heading > div,
    & > div:not(.is-placeholder) {
      // 1 arch
      &:first-child:nth-last-child(2),
      &:first-child:nth-last-child(2) ~ div {
        max-width: 50%;
        width: 50%;
      }

      // 2 arch
      &:first-child:nth-last-child(3),
      &:first-child:nth-last-child(3) ~ div {
        max-width: 33.3333333%;
        width: 33.3333333%;
      }
    }
  }

  // Same again for branches
  .p-releases-table__row--branch > div {
    // 1 arch
    &:first-child:nth-last-child(2).p-releases-channel {
      width: calc(50% - 1rem);
    }

    // 2 arch
    &:first-child:nth-last-child(3).p-releases-channel {
      width: calc(33.333333% - 1rem);
    }
  }

  // channel cell

  .p-releases-channel {
    align-items: flex-start;
    background: $color-light;
    display: flex;
    flex-shrink: 0;
    font-size: 1rem;
    padding: $spv-inner--small $sph-inner--small;
    position: relative;
    width: 280px;

    .p-promote-button {
      font-size: .9rem;
    }

    .has-active & {
      opacity: .5;
    }

    .can-drop &,
    &:hover,
    &.is-active {
      opacity: 1;
    }

    &.is-placeholder {
      background: none;
    }

    .is-over &,
    &.is-highlighted {
      background-color: $color-highlighted;
    }
  }

  .p-releases-channel__name {
    flex-grow: 1;
    max-width: calc(100% - 55px); // leave space handle and settings menu
    padding-right: $sph-inner--small;
  }

  // release cell

  .p-releases-table__cell {
    @include vf-animation (#{background-color, border-color}, 0, in);
    background: $color-light;
    border-bottom: 3px solid transparent;
    flex-basis: 100px;
    flex-grow: 1;
    font-size: 1rem;
    margin-left: 2px;
    max-width: 25.2%; // fill the whole space for 3 archs
    min-width: 100px;
    position: relative;
    transition-duration: 0s; // vf-animation doesn't allow to do that

    .has-active & {
      opacity: .5;
    }

    .can-drop &,
    &.can-drop {
      opacity: 1;
    }

    &.is-clickable {
      cursor: pointer;
    }

    &:focus,
    &:hover,
    &.is-active {
      opacity: 1;
    }

    &.is-active {
      @include vf-animation (#{background-color, border-color}, fast, in);
      background-color: $color-x-light;
      border-color: $color-mid-dark;

      .p-release-data__title {
        font-weight: bold;
      }

      .p-tooltip__message {
        display: none;
      }
    }

    &.is-over,
    .is-over &,
    &.is-highlighted {
      background: $color-highlighted;
    }
  }

  .p-releases-table__arch {
    background: none;
    border: 0;
    padding: ($spv-inner--small - .1rem) $sph-inner--small; // same as p-release-data
  }

  // cell contents (release info)

  .p-release-buttons {
    position: absolute;
    right: .375rem;
    top: .625rem;
  }

  .p-release-data {
    display: flex;
    height: 4rem;
    max-width: 100%;
    padding: $spv-inner--small $sph-inner--small; // p-releases-table__arch
    padding-left: ($sph-inner--small - .1rem);
  }

  .p-release-data__info {
    overflow: hidden;
    white-space: nowrap;

    &.is-pending {
      font-weight: 400;
      padding-right: $sph-outer;
    }
  }

  .p-release-data__icon {
    border-radius: 3px;
    cursor: pointer;
    opacity: 0;
    padding: 0 $sph-inner--small;
    position: absolute;
    right: .5rem;
    top: .5rem;
  }

  .p-release-data:hover {
    .p-release-data__icon {
      opacity: .6;

      &:hover {
        background-color: $color-x-light;
        opacity: 1;
      }
    }
  }

  .p-releases-table__cell.is-active .p-release-data__icon {
    opacity: 1;
  }

  .is-pending {
    .p-release-data__icon {
      margin-right: 1.25rem;
    }
  }

  .p-release-data__info--empty {
    display: inline-block;
    overflow: hidden;
    padding-bottom: .6em;
    padding-top: .6em;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .p-release-data__title,
  .p-release-data__meta {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .p-release-data__meta {
    color: $color-mid-dark;
    font-size: .8rem;
  }

  // REVISIONS LIST

  .p-revisions-list {
    .col-checkbox-spacer {
      padding-left: 2rem;
    }

    .p-revisions-list__row {
      background-color: $color-light;
      border: 0;
      border-bottom: 2px solid $color-x-light;

      &.is-active {
        background-color: $color-x-light;

        .p-revisions-list__revision {
          font-weight: bold;
        }

        .p-revisions-list__revision .p-tooltip__message {
          font-weight: normal;
        }
      }

      &.is-pending {
        background: $color-highlighted;
      }

      &.is-clickable {
        @include vf-animation (#{background-color}, fast, in);
        cursor: pointer;

        &:hover {
          background-color: $color-x-light;
        }
      }
    }

    td:first-of-type,
    th:first-of-type {
      padding-left: .2rem;
    }

    td:last-of-type,
    th:last-of-type {
      padding-right: .5rem;
    }
  }

  // DND
  .is-draggable {
    cursor: grab !important;
  }

  .is-grabbing,
  .is-dragging {
    opacity: .9; // little workaround for chrome

    .p-tooltip__message,
    .p-contextual-menu__dropdown {
      display: none !important; // fighting specificity
    }
  }

  .is-dragging {
    opacity: .5 !important; // fighting specificity
  }

  .p-drag-handle {
    margin-right: $sph-inner--small;
    visibility: hidden;

    .is-draggable & {
      visibility: visible;
    }
  }

  .can-drop {
    outline: 1px dashed $color-mid-light;

    .p-tooltip__message {
      display: none !important;
    }
  }

  // HELPERS

  .p-help {
    border-bottom: 1px dashed $color-mid-dark;
    cursor: help;
  }

  .p-icon-button {
    padding: .1rem .35rem;

    &:not(:last-of-type):not(:only-of-type) {
      margin-right: .25rem;
    }

    // workaround for misaligned Vanilla icon
    // https://github.com/vanilla-framework/vanilla-framework/issues/2085
    & .p-icon--delete {
      left: -1px;
      top: -3px;
    }

    // don't grow these buttons to 100% width on mobile
    @media (max-width: $breakpoint-small) {
      width: auto;
    }
  }

  .p-text-icon {
    display: inline-block;
    width: .875rem;
  }

  .p-action-button {
    background: none;
    border: 0;
    display: block;
    line-height: .875rem;
    padding: 2px 4px;

    .p-icon--close {
      height: .875rem;
      width: .875rem;
    }
  }

  .p-contextual-menu__dropdown {
    overflow: visible; // allow tooltips inside menu
    z-index: 2; // workaround for https://github.com/canonical-web-and-design/vanilla-framework/issues/2577

    .p-tooltip {
      display: block;
    }
  }

  .p-contextual-menu__dropdown.is-wide {
    min-width: 16rem;
  }

  .p-contextual-menu__link {
    color: $color-link;
    padding-bottom: $sp-x-small;
    padding-top: $sp-x-small;
  }

  .p-contextual-menu__link.is-indented {
    padding-left: 1rem;
  }

  .p-contextual-menu__link.is-disabled {
    background: $color-x-light;
    color: $color-mid-dark;
    cursor: not-allowed;
    opacity: .5;
  }

  .p-contextual-menu__item {
    @extend .p-contextual-menu__link; // sass-lint:disable-line placeholder-in-extend
    color: $color-dark;

    &:hover {
      background: transparent;
      cursor: default;
    }
  }

  .p-contextual-menu__description {
    color: $color-dark;
    display: block;
    font-size: .8rem;
    line-height: 1.4;
    margin-bottom: $sp-x-small;
    margin-top: $sp-x-small;
    white-space: normal;
  }

  .p-tooltip__group {
    margin-top: $sp-x-small;
  }

  .p-icon--lp {
    @extend %icon;
    background-image: url("#{$assets-path}ddb379a6-launchpad-logo.svg");
  }

  .p-icon--settings {
    @extend %icon;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='26' height='26'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cpath d='M0 0h26v26H0z'/%3E%3Cpath fill='gray' fill-rule='nonzero' d='M4.401 11.014L2 9.598l2.938-5.196 2.6 1.533a8.746 8.746 0 0 1 2.524-1.423V2h5.876v2.512c.92.332 1.772.817 2.523 1.423l2.601-1.533L24 9.598l-2.401 1.416a9.268 9.268 0 0 1 0 3.972L24 16.402l-2.938 5.196-2.6-1.533a8.746 8.746 0 0 1-2.524 1.423V24h-5.876v-2.512a8.746 8.746 0 0 1-2.523-1.423l-2.601 1.533L2 16.402l2.401-1.416A9.213 9.213 0 0 1 4.186 13c0-.683.074-1.347.215-1.986zM13 18c2.704 0 4.897-2.239 4.897-5S15.704 8 13 8s-4.897 2.239-4.897 5 2.193 5 4.897 5z'/%3E%3C/g%3E%3C/svg%3E");
  }

  .p-icon--drag {
    @extend %icon;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='12' width='12'%3E%3Cpath fill-rule='nonzero' fill='%23666' d='M4 3a1 1 0 1 1 0-2 1 1 0 0 1 0 2zm0 4a1 1 0 1 1 0-2 1 1 0 0 1 0 2zm0 4a1 1 0 1 1 0-2 1 1 0 0 1 0 2zm4-8a1 1 0 1 1 0-2 1 1 0 0 1 0 2zm0 4a1 1 0 1 1 0-2 1 1 0 0 1 0 2zm0 4a1 1 0 1 1 0-2 1 1 0 0 1 0 2z'/%3E%3C/svg%3E");
  }

  .p-icon--history {
    @extend %icon;
    @include snapcraft-icon-history($color-dark);
  }

  .p-icon--branch {
    @extend %icon;
    @include snapcraft-icon-branch($color-dark, "8px", "11px");
    top: 2px;
  }
}
